
function gradeFind(){
    let gradeName = $("#gradeName").val();
    console.log("gradeName"+gradeName)
    layer.open({
        type: 2
        , title: '班级查看学生页面'
        , area: ['1550px', '700px']
        , shade: 0
        , maxmin: true
        , content: "/gradeFindSel/" + gradeName
        , success: function (layero, index) {

        },end: function () {

        }
    })
}
function trimester(){
    let gradeName = $("#gradeId").val();
    layer.open({
        type: 2
        , title: '学生课程信息查看页面'
        , area: ['1550px', '700px']
        , shade: 0
        , maxmin: true
        , content: "/trimesterFind/" + gradeName
        , success: function (layero, index) {

        },end: function () {

        }
    })
}
function dormitoryFind(){
    let dormitoryName = $("#dormitoryName").val();
    console.log("dormitoryName"+dormitoryName)
    layer.open({
        type: 2
        , title: '班级查看学生页面'
        , area: ['1550px', '700px']
        , shade: 0
        , maxmin: true
        , content: "/dormitoryFindSel/" + dormitoryName
        , success: function (layero, index) {

        },end: function () {

        }
    })
}

function button_stuName(){
    $("#stuName").attr("disabled",false);
    $("#stuName").css({
        border:"2px solid #e09e87",
        background:"#bce2e8",
        height:"40px",
        width:"200px",
        textAlign:"center"
    })
    $("#stuName").css("border-radius","10px");
}
function button_sex(){
        var data={
            "stuName":$("#stuName").val(),
            "mobile":$("#mobile").val(),
            "sex":$("#sex").val(),
            "idNum":$("#idNum").val(),
            "provincesId":$("select[name='province']").val(),
            "citiesId":$("select[name='city']").val(),
            "areasId":$("select[name='area']").val(),
            "stuId":$("#stuId").val()
        }
        console.log(data)
        $.ajax({
            type:"post",
            url:"/updatestuName",
            contentType: "application/json;charset=utf-8",
            dataType:"json",
            data:JSON.stringify(data),
            success:function (res) {
                if(res=='1'){
                    layer.msg('修改成功',{icon:6,time:1000},function () {
                        window.location.reload();
                    })
                }else if(res=='0'){
                    layer.msg('修改失败',{icon:5,time:1000},function () {
                        window.location.reload();
                    })
                }
            },error:function (error) {
                layer.msg("修改请求失败")
            }

        })
}
function button_address(){
    var data={
        "stuName":$("#stuName").val(),
        "mobile":$("#mobile").val(),
        "sex":$("#sex").val(),
        "idNum":$("#idNum").val(),
        "provincesId":$("select[name='province']").val(),
        "citiesId":$("select[name='city']").val(),
        "areasId":$("select[name='area']").val(),
        "stuId":$("#stuId").val()
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/updatestuName",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify(data),
        success:function (res) {
            if(res=='1'){
                layer.msg('修改成功',{icon:6,time:1000},function () {
                    window.location.reload();
                })
            }else if(res=='0'){
                layer.msg('修改失败',{icon:5,time:1000},function () {
                    window.location.reload();
                })
            }
        },error:function (error) {
            layer.msg("修改请求失败")
        }

    })
}
$("#stuName").blur(function(){
    var data={
        "stuName":$("#stuName").val(),
        "mobile":$("#mobile").val(),
        "sex":$("#sex").val(),
        "provincesId":$("#province").val(),
        "citiesId":$("#city").val(),
        "areasId":$("#area").val(),
        "idNum":$("#idNum").val(),
        "stuId":$("#stuId").val(),
        "stuNum":$("#stuNum").val()
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/updatestuName",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify(data),
        success:function (res) {
            if(res=='1'){
                layer.msg('修改成功',{icon:6,time:1000},function () {
                    window.location.reload();
                })
            }else if(res=='0'){
                layer.msg('修改失败',{icon:5,time:1000},function () {
                    window.location.reload();
                })
            }
        },error:function (error) {
            layer.msg("修改请求失败")
        }

    })
})
$("#idNum").blur(function(){
    var data={
        "stuName":$("#stuName").val(),
        "mobile":$("#mobile").val(),
        "sex":$("input[name='sex'].selected").val(),
        "idNum":$("#idNum").val(),
        "provincesId":$("select[name='province']").val(),
        "citiesId":$("select[name='city']").val(),
        "areasId":$("select[name='area']").val(),
        "stuId":$("#stuId").val()
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/updatestuName",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify(data),
        success:function (res) {
            if(res=='1'){
                layer.msg('修改成功',{icon:6,time:1000},function () {
                    window.location.reload();
                })
            }else if(res=='0'){
                layer.msg('修改失败',{icon:5,time:1000},function () {
                    window.location.reload();
                })
            }
        },error:function (error) {
            layer.msg("修改请求失败")
        }

    })
})
$("#mobile").blur(function(){
    var data={
        "stuName":$("#stuName").val(),
        "mobile":$("#mobile").val(),
        "sex":$("input[name='sex'].selected").val(),
        "idNum":$("#idNum").val(),
        "provincesId":$("select[name='province']").val(),
        "citiesId":$("select[name='city']").val(),
        "areasId":$("select[name='area']").val(),
        "stuId":$("#stuId").val()
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/updatestuName",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify(data),
        success:function (res) {
            if(res=='1'){
                layer.msg('修改成功',{icon:6,time:1000},function () {
                    window.location.reload();
                })
            }else if(res=='0'){
                layer.msg('修改失败',{icon:5,time:1000},function () {
                    window.location.reload();
                })
            }
        },error:function (error) {
            layer.msg("修改请求失败")
        }

    })
})
$("#email").blur(function(){
    var data={
        "stuName":$("#stuName").val(),
        "mobile":$("#mobile").val(),
        "sex":$("input[name='sex'].selected").val(),
        "idNum":$("#idNum").val(),
        "provincesId":$("select[name='province']").val(),
        "citiesId":$("select[name='city']").val(),
        "areasId":$("select[name='area']").val(),
        "stuId":$("#stuId").val()
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/updatestuName",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify(data),
        success:function (res) {
            if(res=='1'){
                layer.msg('修改成功',{icon:6,time:1000},function () {
                    window.location.reload();
                })
            }else if(res=='0'){
                layer.msg('修改失败',{icon:5,time:1000},function () {
                    window.location.reload();
                })
            }
        },error:function (error) {
            layer.msg("修改请求失败")
        }

    })
})
// $("#province").blur(function(){
//     var data={
//         "stuName":$("#stuName").val(),
//         "mobile":$("#mobile").val(),
//         "sex":$("input[name='sex'].selected").val(),
//         "idNum":$("#idNum").val(),
//         "provincesId":$("select[name='province']").val(),
//         "citiesId":$("select[name='city']").val(),
//         "areasId":$("select[name='area']").val(),
//         "stuId":$("#stuId").val()
//     }
//     console.log(data)
//     $.ajax({
//         type:"post",
//         url:"/updatestuName",
//         contentType: "application/json;charset=utf-8",
//         dataType:"json",
//         data:JSON.stringify(data),
//         success:function (res) {
//             if(res=='1'){
//                 layer.msg('修改成功',{icon:6,time:1000},function () {
//                     window.location.reload();
//                 })
//             }else if(res=='0'){
//                 layer.msg('修改失败',{icon:5,time:1000},function () {
//                     window.location.reload();
//                 })
//             }
//         },error:function (error) {
//             layer.msg("修改请求失败")
//         }
//
//     })
// })
// $("#city").blur(function(){
//     var data={
//         "stuName":$("#stuName").val(),
//         "mobile":$("#mobile").val(),
//         "sex":$("input[name='sex'].selected").val(),
//         "idNum":$("#idNum").val(),
//         "provincesId":$("select[name='province']").val(),
//         "citiesId":$("select[name='city']").val(),
//         "areasId":$("select[name='area']").val(),
//         "stuId":$("#stuId").val()
//     }
//     console.log(data)
//     $.ajax({
//         type:"post",
//         url:"/updatestuName",
//         contentType: "application/json;charset=utf-8",
//         dataType:"json",
//         data:JSON.stringify(data),
//         success:function (res) {
//             if(res=='1'){
//                 layer.msg('修改成功',{icon:6,time:1000},function () {
//                     window.location.reload();
//                 })
//             }else if(res=='0'){
//                 layer.msg('修改失败',{icon:5,time:1000},function () {
//                     window.location.reload();
//                 })
//             }
//         },error:function (error) {
//             layer.msg("修改请求失败")
//         }
//
//     })
// })
$("#areas").blur(function(){
    var data={
        "stuName":$("#stuName").val(),
        "mobile":$("#mobile").val(),
        "sex":$("input[name='sex'].selected").val(),
        "idNum":$("#idNum").val(),
        "provincesId":$("select[name='province']").val(),
        "citiesId":$("select[name='city']").val(),
        "areasId":$("select[name='area']").val(),
        "stuId":$("#stuId").val()
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/updatestuName",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        data:JSON.stringify(data),
        success:function (res) {
            if(res=='1'){
                layer.msg('修改成功',{icon:6,time:1000},function () {
                    window.location.reload();
                })
            }else if(res=='0'){
                layer.msg('修改失败',{icon:5,time:1000},function () {
                    window.location.reload();
                })
            }
        },error:function (error) {
            layer.msg("修改请求失败")
        }

    })
})
function button_idNum(){
    $("#idNum").attr("disabled",false);
    $("#idNum").css({
        border:"2px solid #e09e87",
        background:"#bce2e8",
        height:"40px",
        width:"200px",
        textAlign:"center"
    })
    $("#idNum").css("border-radius","10px");
}
function button_mobile(){
    $("#mobile").attr("disabled",false);
    $("#mobile").css({
        border:"2px solid #e09e87",
        background:"#bce2e8",
        height:"40px",
        width:"200px",
        textAlign:"center"
    })
    $("#mobile").css("border-radius","10px");
}
function button_email(){
    $("#email").attr("disabled",false);
    $("#email").css({
        border:"2px solid #e09e87",
        background:"#bce2e8",
        height:"40px",
        width:"200px",
        textAlign:"center"
    })
    $("#email").css("border-radius","10px");
}

var provinceId = $("#provinceId").val();
layui.use(['form'],function () {
    // 省下拉框
    $.ajax({
        type:"post",
        url:"provinces",
        contentType: "application/json;charset=utf-8",
        dataType:"json",
        success:function (plist) {
            var phtml ="<option value=''>请选择1</option>";
            for (let i = 0; i < plist.length; i++) {
                phtml += "<option value="+plist[i].provinceid+">"+plist[i].province+"</option>";
            }

            layui.layer.msg(phtml);
            $("#province").html(phtml);

            console.log($("#provincesIdh").val());
            $("#province").val($("#provincesIdh").val());


            // console.log(111);

            layui.form.render('select'); //这个很重要,没有这个新的option不会显示
            // layer.msg(data.)

        },error:function () {
            layer.msg("添加请求失败1");
        }
    });

    //市下拉框
    $.ajax({
        type: "post",
        url:  "cities",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (clist) {
            layer.msg("1");
            var chtml = "<option value=''>请选择1</option>";
            for (let i = 0; i < clist.length; i++) {
                if ($("#province").val() == clist[i].provinceid) {
                    chtml += "<option value=" + clist[i].cityid + ">" + clist[i].city + "</option>";
                }
            }
            $("#city").html(chtml);
            $("#city").val($("#citiesIdh").val());
            layui.form.render('select'); //这个很重要,没有这个新的option不会显示
            layer.msg(chtml);

        }, error: function () {
            layer.msg("添加请求失败2");
        }
    });

    //区下拉框
    $.ajax({
        type: "post",
        url:  "areas",
        contentType: "application/json;charset=utf-8",
        dataType: "json",
        success: function (alist)   {
            var ahtml = "<option value=''>请选择1</option>";
            for (let i = 0; i < alist.length; i++) {
                if ($("select[name='city']").val() == alist[i].cityid) {
                    ahtml += "<option value=" + alist[i].areaid + ">" + alist[i].area + "</option>";
                }
            }
            $("select[name='area']").html(ahtml);
            $("select[name='area']").val($("#areaidh").val());
            layer.msg(ahtml);
            layui.form.render('select'); //这个很重要,没有这个新的option不会显示
        }, error: function () {
            layer.msg("添加请求失败3");
        }
    });

    //当select发生改变时
    layui.form.on('select(province)', function (dat) {
        $("#city").empty();
        $("#area").empty();

        //市下拉框
        $.ajax({
            type: "post",
            url:"cities",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (clist) {
                layer.msg("1");
                var chtml = "<option value=''>请选择1</option>";
                for (let i = 0; i < clist.length; i++) {
                    if ($("select[name='province']").val() == clist[i].provinceid) {
                        chtml += "<option value=" + clist[i].cityid + ">" + clist[i].city + "</option>";
                    }
                }
                $("select[name='city']").html(chtml);

                layui.form.render('select'); //这个很重要,没有这个新的option不会显示
                layer.msg(chtml);

            }, error: function () {
                layer.msg("添加请求失败2");
            }
        });
    });

    //当select发生改变时
    layui.form.on('select(city)', function (dat) {
        $.ajax({
            type: "post",
            url: "areas",
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (alist) {
                var ahtml = "<option value=''>请选择1</option>";
                for (let i = 0; i < alist.length; i++) {
                    if ($("#city").val() == alist[i].cityid) {
                        ahtml += "<option value=" + alist[i].areaid + ">" + alist[i].area + "</option>";
                    }
                }
                $("select[name='area']").html(ahtml);

                layer.msg(ahtml);
                layui.form.render('select'); //这个很重要,没有这个新的option不会显示
            }, error: function () {
                layer.msg("添加请求失败3");
            }
        });




    });
});









